/*************************************************
Author: will
Date: 9/11/2012
Description:
Notes: 
*************************************************/

#ifndef __CTaskMgr_h__
#define __CTaskMgr_h__

#include "CTaskConfig.h"
#include "CUserDataInf.h"
#include "CUserTask.h"
#include "CRewardTask.h"

class MsgOneTask;
class MsgTaskTarget;
class CTaskOpenTriggerInf;
class MsgAnsGetTaskList;
class CPlayerOnlineData;
class CTaskMgr
{
public:
	CTaskMgr(CUserDataInf& stUserDataInf)
        :_stUserDataInf(stUserDataInf)
    {
	}

	virtual ~CTaskMgr() 
    {
	}

    int Init();
    int LoadConfig(const char* szLogPath);

    int AddConfig(CTaskConfigData& stConfigData);
    int SetTaskTime(CUserTask& stUserTask, CTaskID& stTaskID, int iEndTime);

    int GetTaskIDStruct(int iTaskID, CTaskID& stTaskID);

    int GetTaskConfig(CTaskID& stTaskID, CTaskConfigData& stTaskConfigData);

    //接受任务
    int AcceptTask(CTaskID& stTaskID, CUserTask& stUserTask);

    //提交任务
    int CommitTask(CTaskID& stTaskID, CUserTask& stUserTask);

    //等待激活的任务
    int WaitForOpenTask(CTaskID& stTaskID, CUserTask& stUserTask);

    //使用用户数据主动做一次触发
    int UserDataTrigger(CUserTask& stUserTask);

    //检查有无需要被自动接取的任务
    int CheckTaskNeedToAccept(CUserTask& stUserTask);

    int TriggerLevelUp(CUserTask& stUserTask, int iNowLevel);
    int TriggerTaskFinish(CUserTask& stUserTask, CTaskID& stTaskID);
    int TriggerPetLevelUp(CUserTask& stUserTask, int iNowPetLevel);
    int TriggerBossConquer(CUserTask& stUserTask, int iBossID, int iCount);
    int TriggerKillEnemy(CUserTask& stUserTask, int iEnemyID, int iCount);
    int TriggerDoSomeOpt(CUserTask& stUserTask, int iOptID, int iCount);
    int TriggerUseItem(CUserTask& stUserTask, unsigned char ucItemType, unsigned short usItemID, int iCount);
    int TriggerGetItem(CUserTask& stUserTask, unsigned char ucItemType, unsigned short usItemID, int iCount);
    int TriggerFinishInstance(CUserTask& stUserTask, int iInstanceID, int iCount);
    int TriggerTaskAward(CUserTask& stUserTask, CTaskConfigData& curTaskCfgData);

    bool IsTaskFinished(CUserTask& stUserTask, CTaskID& stTaskID);
    bool IsTaskAccepted(CUserTask& stUserTask, CTaskID& stTaskID);

    CUserDataInf& GetUserDataInf() {return _stUserDataInf;}

    //检查任务是否过期
    void CheckTaskExpire(CUserTask& stUserTask);  

    //GM Command
    int GMSetTaskFinished(int iTaskID, CUserTask& stUserTask);
    int GMAddFollowTasks(CTaskConfigData& stFollowTaskConfigData, CUserTask& stUserTask);

    int GetTaskInfo(CUserTask& stUserTask, CTaskID& stTaskID, MsgOneTask& stAnsInfo);
    void GetTaskList(CUserTask& stUserTask, MsgAnsGetTaskList& stTaskListAns);
    int GetTargetDetailInfo(unsigned int uiGID, MsgTaskTarget& stTaskTarget, CTaskTargetStatData& stTargetStatData);

    //悬赏令任务: 查询列表
    void GetRewardTaskList(unsigned int uiGID, MsgAnsAwardTask& stAns);

    //悬赏令任务: 查询悬赏令信息
    void GetRewardTaskInfo(CRewardTask& stRewardTask, unsigned int uiGID, MsgAnsAwardTask& stAns);

    //悬赏令任务: 查询我的悬赏任务信息
    void GetMyRewardTaskList(CRewardTask& stRewardTask, unsigned int uiGID, MsgAnsAwardTask& stAns);

    //悬赏令任务: 发布
    int PublishRewardTask(CRewardTask& stRewardTask, unsigned char ucRewardType, CPlayerBaseInfo& stPlayerBaseInfo, CPlayerOnlineData& stPlayerOnlineData);

    //悬赏令任务：接任务
    int AcceptRewardTask(CRewardTask& stAcceptRewardTask, CRewardTask& stPublishRewardTask,
        CPlayerOnlineData& stAcceptOnlineData, 
        int iPublishTime, unsigned int uiPublishGID, MsgAnsAwardTask& stAns);

    //悬赏令任务：提交任务
    int CommitRewardTask(CTaskID& stTaskID, CRewardTask& stPublishRewardTask,
                    CPlayerOnlineData& stAcceptOnlineData);

    //悬赏令任务：领取发布奖励
    int GetRewardTaskBonus(CRewardTask& stRewardTask, unsigned int uiGID, int iPublishTime, MsgAnsAwardTask& stAns);

    //悬赏令任务: 启动的时候初始化
    int InitRewardTask(CRewardTask& stRewardTask, unsigned int uiGID);

    //悬赏令任务: 获取发布者GID
    unsigned int GetRewardTaskPublishGID(CUserTask& stUserTask, CTaskID& stTaskID);

private:
	CTaskConfig _stTaskConfig;
    CUserDataInf& _stUserDataInf;
    CRewardTaskConfig _stRewardTaskConfig;

    CRewardTaskList _stRewardTaskList;       //悬赏令任务_公告板
};


#endif // __CTaskMgr_h__

